INCLUDE_DIRECTORIES(".")

# List sources files
FILE(GLOB LIBRARY_FILES_C "*.cpp")
FILE(GLOB LIBRARY_FILES_H "*.h" "*.inl")

FILE(GLOB IBFS_LIBRARY_FILES_C "IBFS/*.cpp")
FILE(GLOB IBFS_LIBRARY_FILES_H "IBFS/*.h" "IBFS/*.inl")
SOURCE_GROUP("IBFS" FILES ${IBFS_LIBRARY_FILES_C} ${IBFS_LIBRARY_FILES_H})

FILE(GLOB LMFit_LIBRARY_FILES_C "LMFit/*.cpp")
FILE(GLOB LMFit_LIBRARY_FILES_H "LMFit/*.h" "LMFit/*.inl")
SOURCE_GROUP("LMFit" FILES ${LMFit_LIBRARY_FILES_C} ${LMFit_LIBRARY_FILES_H})

FILE(GLOB TRWS_LIBRARY_FILES_C "TRWS/*.cpp")
FILE(GLOB TRWS_LIBRARY_FILES_H "TRWS/*.h" "TRWS/*.inl")
SOURCE_GROUP("TRWS" FILES ${TRWS_LIBRARY_FILES_C} ${TRWS_LIBRARY_FILES_H})

cxx_library_with_type(Math "Libs" "" "${cxx_default}"
	${LIBRARY_FILES_C} ${LIBRARY_FILES_H}
	${IBFS_LIBRARY_FILES_C} ${IBFS_LIBRARY_FILES_H}
	${LMFit_LIBRARY_FILES_C} ${LMFit_LIBRARY_FILES_H}
	${TRWS_LIBRARY_FILES_C} ${TRWS_LIBRARY_FILES_H}
)

# Manually set Common.h as the precompiled header
IF(CMAKE_VERSION VERSION_GREATER_EQUAL 3.16.0)
	TARGET_PRECOMPILE_HEADERS(Math PRIVATE "Common.h")
endif()

# Link its dependencies
TARGET_LINK_LIBRARIES(Math Common)

# Install
INSTALL(FILES ${LIBRARY_FILES_H} DESTINATION "${INSTALL_INCLUDE_DIR}/Math")
INSTALL(FILES ${IBFS_LIBRARY_FILES_H} DESTINATION "${INSTALL_INCLUDE_DIR}/Math/IBFS")
INSTALL(FILES ${LMFit_LIBRARY_FILES_H} DESTINATION "${INSTALL_INCLUDE_DIR}/Math/LMFit")
INSTALL(FILES ${TRWS_LIBRARY_FILES_H} DESTINATION "${INSTALL_INCLUDE_DIR}/Math/TRWS")
INSTALL(TARGETS Math
	EXPORT OpenMVSTargets
	LIBRARY DESTINATION "${INSTALL_LIB_DIR}"
	ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
	RUNTIME DESTINATION "${INSTALL_BIN_DIR}"
	PUBLIC_HEADER DESTINATION "${INSTALL_INCLUDE_DIR}/Math")
